package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.ApplyToProgDepAddDTO;
import org.jsola.hr.dto.ApplyToProgDepUpdateDTO;
import org.jsola.hr.entity.ApplyToProgDepDO;
import org.jsola.hr.query.ApplyToProgDepQuery;
import org.jsola.hr.service.IApplyToProgDepService;
import org.jsola.hr.vo.ApplyToProgDepVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class ApplyToProgDepTestHelper extends BaseTestHelper {
    
    @Autowired
    private IApplyToProgDepService applyToProgDepService;

    /**
     * 生成add测试数据
     * @return ApplyToProgDepAddDTO
     */
    public ApplyToProgDepAddDTO getApplyToProgDepAddDTO(){
        ApplyToProgDepAddDTO applyToProgDepAddDTO = new ApplyToProgDepAddDTO();
        applyToProgDepAddDTO.setProgId(getRandomValue("varchar",32));
        applyToProgDepAddDTO.setDepId(getRandomValue("varchar",32));
        applyToProgDepAddDTO.setType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        applyToProgDepAddDTO.setCompanyId(getRandomValue("varchar",32));
        return applyToProgDepAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ApplyToProgDepUpdateDTO
     */
    public ApplyToProgDepUpdateDTO getApplyToProgDepUpdateDTO(ApplyToProgDepVO applyToProgDepVO){
        return applyToProgDepService.selectDOById(applyToProgDepVO.getId(), SITE_ID).to(ApplyToProgDepUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ApplyToProgDepQuery
     */
    public ApplyToProgDepQuery getApplyToProgDepQuery() {
        ApplyToProgDepQuery applyToProgDepQuery = new ApplyToProgDepQuery();
        List<ApplyToProgDepDO> applyToProgDepDOList = applyToProgDepService.list(new ApplyToProgDepDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(applyToProgDepDOList)) {
            ApplyToProgDepDO applyToProgDepDO = applyToProgDepDOList.get(0);
            applyToProgDepQuery = applyToProgDepDO.to(ApplyToProgDepQuery.class);
            if (applyToProgDepDO.getGmtCreate() != null) {
                applyToProgDepQuery.setGmtCreateStart(DateKit.getBeforeDay(applyToProgDepDO.getGmtCreate(),-1));
                applyToProgDepQuery.setGmtCreateEnd(DateKit.getBeforeDay(applyToProgDepDO.getGmtCreate(),1));
            }
        }
        return applyToProgDepQuery;
    }

    /**
     * 保存示例
     * @return ApplyToProgDepVO
     */
    public ApplyToProgDepVO saveApplyToProgDepExample(){
        ApplyToProgDepAddDTO addDTO = this.getApplyToProgDepAddDTO();
        ApplyToProgDepVO applyToProgDepVO = applyToProgDepService.save(addDTO,buildTokenUser());
        return applyToProgDepVO;
    }


}

